import java.util.Iterator;
import java.util.LinkedHashSet;

public class LinkedHashSetTest {
    public static void main(String[] args) {
        LinkedHashSet<Person> linkedHashSet = new LinkedHashSet<>();

        Person p1 = new Person("abc", 18);
        Person p2 = new Person("def", 18);
        Person p3 = new Person("abc", 24);
        Person p4 = new Person("xy", 20);

        linkedHashSet.add(p1);
        linkedHashSet.add(p2);
        linkedHashSet.add(p3);
        linkedHashSet.add(p4);

        Person p5 = new Person("abc", 18);
        linkedHashSet.add(p5);

        Iterator<Person> iterator = linkedHashSet.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }

}
